package com.itheima.reggie.mapper;

import com.itheima.reggie.dto.SetmealDto;
import com.itheima.reggie.entity.Dish;
import com.itheima.reggie.entity.Setmeal;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

public interface SetmealMapper{
    @Select("select count(*) from setmeal where category_id=#{cid} and is_deleted=0")
    Integer countBySetmeal(Long cid);

    @Insert("insert into setmeal values (null,#{categoryId},#{name},#{price},#{status},#{code},#{description}," +
            "#{image},#{createTime},#{updateTime},#{createUser},#{updateUser},0)")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    Integer save(SetmealDto setmealDto);

    //查询套餐和分类
    List<SetmealDto> findAll(String name);

    //查询套餐中起售的数量
    Integer countByIds(@Param("ids") Long[] ids);
    //批量删除
    Integer delete(@Param("ids") Long[] ids, @Param("updateUser") Long updateUser,@Param("updateTime") LocalDateTime updateTime);

    //根据id改变售卖状态
    Integer updateStatusById(@Param("ids") Long[] ids,@Param("status") Integer status);

    //根据id改变售卖状态

   // Integer updateStatusById2(@Param("ids") Long[] ids);

    //数据回显
    SetmealDto findById(Long id);
    //修改
    Integer updateById(SetmealDto setmealDto);

    //根据分类id查询套餐
    @Select("select * from setmeal where category_id = #{categoryId} and status = #{status} and is_deleted=0")
    List<Setmeal> findByCategoryIdAndStatus(@Param("categoryId") Long categoryId, @Param("status") Integer status);
}
